package com.heima.article.listener;

import cn.hutool.json.JSONUtil;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.common.UpDownMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
public class ArticleIsDownListener {
    @Resource
    private ApArticleConfigService apArticleConfigService;

    @KafkaListener
    public void OnMessage(String msg) {
        assert msg != null;
        //接收的json转换为对象
        UpDownMsg upDownMsg = JSONUtil.toBean(msg, UpDownMsg.class);
        //调用方法进行修改文章的enable
        boolean updated = apArticleConfigService.updateArticleEnable(upDownMsg);
        if (updated) {
            log.info("article更新完成");
        }
    }
}
